package com.skirmisher.inspection.common.controller;

import com.skirmisher.inspection.common.entity.InsJobPlaceLogEntity;
import com.skirmisher.inspection.common.entity.InsPlaceLog;
import com.skirmisher.inspection.common.service.InsPlaceLogService;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName InsPlaceLogController
 * @Description TODO巡查位置上传
 * @Author hanwangxin
 * @Date 2020/12/13 下午4:47
 * @Version 1.0
 */
@Api(tags = "巡查路基接口")
@RestController
@RequestMapping("/placeLog")
public class InsPlaceLogController {

    @Autowired
    private InsPlaceLogService insPlaceLogService;

    /**
     * @Author hanwangxin
     * @Description //TODO 上传路径地点信息 * @Date 下午4:55 2020/12/13
     * @Param [placeLog]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "上传路径")
    @PostMapping(value = "/updatePlaceLog")
    public ResponseModel updatePlaceLog(@RequestBody @Validated InsPlaceLog placeLog){

        ResponseModel responseModel = new ResponseModel();

        insPlaceLogService.updatePlaceLog(placeLog);

        return responseModel;
    }

    @ApiOperation(value = "获取任务的路径图")
    @GetMapping(value = "/getPalceLog")
    public ResponseModel getPalceLog(String jobId){
        ResponseModel responseModel = new ResponseModel();

        if (StringUtils.isEmpty(jobId)){
            responseModel.setCode(201);
            responseModel.setMessage("无任务id");
            return responseModel;
        }

        List<InsJobPlaceLogEntity> placeLog = insPlaceLogService.getPalceLog(jobId);
        responseModel.setData(placeLog);

        return responseModel;
    }
}
